package com.schoolCommunity.controller;

import com.schoolCommunity.pojo.Information;
import com.schoolCommunity.pojo.MailboxAdmin;
import com.schoolCommunity.pojo.MailboxMember;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

@RestController
public class MailboxController {

    @Autowired
    private RestTemplate restTemplate;

    private static final String REST_URL_PREFIX = "http://SCHOOLCOMMUNITY-MAILBOX";

    //负载均衡测试用
    @GetMapping("/MailboxHello")
    public String hello() {
        System.out.println("-------------------进入了测试--------------");
        return restTemplate.getForObject(REST_URL_PREFIX + "/hello", String.class);
    }

    //用户给管理员发送邮箱
    @PostMapping("/SendToAdmin")
    public Information SendToAdmin(@RequestBody MailboxAdmin mailboxAdmin) {
        System.out.println("========================================进入了======");
        return restTemplate.postForObject(REST_URL_PREFIX + "/SendToAdmin", mailboxAdmin, Information.class);
    }

    //用户获取自己发送的邮箱
    @GetMapping("/GetSendFromMember/{memberId}")
    public Information GetSendFromMember(@PathVariable("memberId") long memberId) {
        return restTemplate.getForObject(REST_URL_PREFIX + "/GetSendFromMember/" + memberId, Information.class);
    }

    //管理员获取还没有查看的邮箱
    @GetMapping("/GetNoReadMailToAdmin/{adminId}")
    public Information GetNoReadMailToAdmin(@PathVariable("adminId") long adminId) {
        return restTemplate.getForObject(REST_URL_PREFIX + "/GetNoReadMailToAdmin/" + adminId, Information.class);
    }

    //管理员获取所有收到的邮箱
    @GetMapping("/GetAllMail/{adminId}")
    public Information GetAllMail(@PathVariable("adminId") long adminId) {
        return restTemplate.getForObject(REST_URL_PREFIX + "/GetAllMail/" + adminId, Information.class);
    }

    //用户获取尚未阅读的邮件
    @GetMapping("/memberGetNoMail/{memberId}")
    public Information memberGetNoMail(@PathVariable("memberId") long memberId) {
        return restTemplate.getForObject(REST_URL_PREFIX + "/memberGetNoMail/" + memberId, Information.class);
    }

    //用户获取所有邮件
    @GetMapping("/memberAllMail/{memberId}")
    public Information memberAllMail(@PathVariable("memberId") long memberId) {
        return restTemplate.getForObject(REST_URL_PREFIX + "/memberAllMail/" + memberId, Information.class);
    }


    //管理员写邮件给用户
    @PostMapping("/mailboxMember")
    public Information adminSendToMember(@RequestBody MailboxMember mailboxMember) {
        return restTemplate.postForObject(REST_URL_PREFIX + "/mailboxMember", mailboxMember, Information.class);
    }

    //管理员获取自己发送出去的邮箱
    @GetMapping("/GetSendFromAdmin/{adminId}")
    public Information GetSendFromAdmin(@PathVariable("adminId") long adminId) {
        return restTemplate.getForObject(REST_URL_PREFIX + "/GetSendFromAdmin/" + adminId, Information.class);
    }


//    @RequestMapping("/consumer/dept/get/{id}")
//    public Dept queryBtId(@PathVariable("id") Long id) {
//        return restTemplate.getForObject(REST_URL_PREFIX + "/dept/queryById/" + id, Dept.class);
//    }
//
//    @RequestMapping("/consumer/dept/add")
//    public boolean add(Dept dept) {
//        return restTemplate.postForObject(REST_URL_PREFIX + "/dept/add" ,dept , Boolean.class);
//    }
//
//    @RequestMapping("/consumer/dept/list")
//    public List<Dept> queryAll(){
//        return restTemplate.getForObject(REST_URL_PREFIX+"/dept/queryAll", List.class);
//    }

}

